					//22th Oct 2018
var ShowMe={};
var Utils={};
Utils.Path='';
Utils.mobileDeviceFlag=false;
var questionId=0,startTime=0,scoredMarks=0,resId=0,totalMarks=10;
ShowMe.skipedQ=0;
ShowMe.alreadyShownObject=[];
//function for loader
$(document).ready(function(){
	$(".se-pre-con").fadeOut("slow");
	if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
		Utils.mobileDeviceFlag=true;
//	if(Utils.mobileDeviceFlag)
	//	Utils.Path=Android.getMediaPath(""); 
	setTimeout(function(){
		document.getElementById('coverpage').style.display="block";
		document.getElementById('gamepage').style.display="none";
		document.getElementById('endpage').style.display="none";
		document.getElementById("homeImg").style.display = "none";
		ShowMe.setImages();
	},300);
});
ShowMe.setImages=function()
{
	document.body.style.backgroundImage="url("+Utils.Path+ShowMe.coverImage+")";
	document.getElementById("homeImg").src=Utils.Path+"images/Home.png";
	document.getElementById("logoImg").src=Utils.Path+"images/logo.png";
	document.getElementById("playImg").src=Utils.Path+"images/Play.png";
	document.getElementById("nextImage").src=Utils.Path+"images/Next.png";
	document.getElementById("sound").src=Utils.Path+"images/Sound.png";
}
ShowMe.playGame=function()
{
	document.getElementById('coverpage').style.display="none";
	document.getElementById('gamepage').style.display="none";
	document.getElementById("homeImg").style.display = "block";
	var middlepage=document.getElementById("middlepage");
	ShowMe.createDivs(middlepage,"level");
	ShowMe.createDivs(showMePageDiv,"picture");
	//ShowMe.showObjects();
}
//creates No. of Divs
ShowMe.createDivs=function(parentDiv,id)
{
	var ShowMeDiv,pictureDiv,img;
	for(var j=0;j<3;j++)
	{
		pictureDiv= document.createElement("div");
		pictureDiv.setAttribute("id",id+j); 
		pictureDiv.setAttribute("class","borderClass pointerClass noPadding col-md-3 col-xs-3 col-lg-3 col-sm-3  col-lg-offset-1 col-md-offset-1 col-sm-offset-1 col-xs-offset-1"); 
		//pictureDiv.setAttribute("onclick","ShowMe.checkAnswer(this)"); 
		parentDiv.appendChild(pictureDiv);

		img=document.createElement('img');
		img.setAttribute("id",id+"img"+j); 
		img.setAttribute("class","noPadding img-responsive col-lg-12 col-md-12 col-xs-12 col-sm-12");
		
		pictureDiv.appendChild(img);
		if(parentDiv==middlepage)
		{
			img.setAttribute("src",ShowMe.levelImg.imgName+j+ShowMe.levelImg.imgType);
			$(img).data("ans",j);
			img.setAttribute("onclick","ShowMe.showObjects(this)"); 
		}
		else
			img.setAttribute("onclick","ShowMe.checkAnswer(this)"); 
	}
}
//Show Objects on the screen
ShowMe.showObjects=function(element)
{
	var d,imgCnt=0;
	d=new Date();
	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();document.getElementById("correctWrongDiv").style.visibility="hidden";
	ShowMe.uniqueImgArr=[];
	ShowMe.uniqueImgArr=populate(ShowMe.data[0].levelData[$(element).data("ans")].list,ShowMe.uniqueImgArr,ShowMe.data[0].number);
	for(var j=0;j<3;j++)
	{
		$("#pictureimg"+j).prop("src",Utils.Path+"images/"+ShowMe.uniqueImgArr[imgCnt].imgName);
		$("#picture"+j).data("ans",ShowMe.uniqueImgArr[imgCnt].name);
		imgCnt++;
	}
	ShowMe.uniqueQue= Math.floor(Math.random()*(ShowMe.uniqueImgArr.length));
	while($.inArray(ShowMe.uniqueImgArr[ShowMe.uniqueQue].name,ShowMe.alreadyShownObject)!==-1)
		ShowMe.uniqueQue= Math.floor(Math.random()*(ShowMe.uniqueImgArr.length));
	ShowMe.alreadyShownObject.push(ShowMe.uniqueImgArr[ShowMe.uniqueQue].name);
	console.log(ShowMe.uniqueImgArr[ShowMe.uniqueQue].name);
	ShowMe.playInstruction();
}
ShowMe.playInstruction=function()
{
	var duration;
	clearTimeout(ShowMe.myTimer);
	document.getElementById('playSound').pause();
	$(".pointerClass").css("pointer-events","none");
	document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.data[0].instruction;
	ShowMe.instruction=setTimeout(function()
	{
		duration=document.getElementById('playSound').duration;
		document.getElementById('playSound').play();
		if(ShowMe.myTimer)
		{
			clearTimeout(ShowMe.myTimer);
			ShowMe.myTimer=null;
		}
		ShowMe.myTimer=setTimeout(function()
		{
			document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.uniqueImgArr[ShowMe.uniqueQue].sound;
			document.getElementById('playSound').play();
		},duration*1000);
		setTimeout(function(){
			$(".pointerClass").css("pointer-events","auto");
		},duration*1500);
	},500);
	questionId=parseInt(ShowMe.uniqueImgArr[ShowMe.uniqueQue].questionId);
}
//Check Answer
ShowMe.checkAnswer=function(element)
{	
	var randomSound;
	document.getElementById("correctWrongDiv").style.visibility="visible";
	if(($(element).data('ans')==ShowMe.uniqueImgArr[ShowMe.uniqueQue].name))
	{
		scoredMarks=10;
		document.getElementById('correctWrongImg').src=Utils.Path+"images/correct.png";
		randomSound=Math.floor(Math.random()*(ShowMe.correctAns.length));
		document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.correctAns[randomSound];
		document.getElementById('playSound').play();
		$(".pointerClass").css("pointer-events","none");
		ShowMe.nextQ=setTimeout(function(){
			ShowMe.nextStory();
		},1500);
	}
	else
	{
		scoredMarks=0;
		document.getElementById('correctWrongImg').src=Utils.Path+"images/wrong.png";
		randomSound=Math.floor(Math.random()*(ShowMe.wrongAns.length));
		document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.wrongAns[randomSound];
		document.getElementById('playSound').play();
		setTimeout(function(){
			document.getElementById("correctWrongDiv").style.visibility="hidden";
		},1500);
	}
	console.log(resId,questionId,scoredMarks,totalMarks,1,startTime);
	if(Utils.mobileDeviceFlag)
		console.log(resId,questionId,scoredMarks,totalMarks,1,startTime);
}
//Load Next Question Of The Same Story
ShowMe.nextStory=function()
{
	ShowMe.skipedQ++;
	clearTimeout(ShowMe.instruction);
	clearTimeout(ShowMe.myTimer);
	clearTimeout(ShowMe.nextQ);
	document.getElementById('playSound').pause();
	if(ShowMe.skipedQ==5)
	{
		document.getElementById("gamepage").style.display="none";
		$('#endpage').show();
		document.getElementById('conceptDiv').innerHTML=ShowMe.hardcorded.ConceptBy;
		document.getElementById('artWorkDiv').innerHTML=ShowMe.hardcorded.ArtWork;
		document.getElementById('audioRecordingDiv').innerHTML=ShowMe.hardcorded.AudioRecording;
		document.getElementById('musicgDiv').innerHTML=ShowMe.hardcorded.Music;
		document.getElementById('developerNameDiv').innerHTML=ShowMe.hardcorded.DevelopedBy;
	}
	else
		ShowMe.showObjects();
}